package org.example.anno_ioc_di;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author 李新雨的项目86176
 * @version 1.0
 * @date 2024-11-11 16:20
 */
public class Person {
    /**
     * DI 注解之 Autowired 和 Value 注解 :字段或者setXxx方法上
     *
     * 使用注解满足的条件--------------------------
     * 1.注解本身的作用
     * 2.贴在哪里
     * 3.解析注解---------注解解析程序的对象
     *
     */
    @Value("李某")
    private String name;

    @Value("18")
    private int age;

    /**
     * 先按照类型Class在spring容器中找，如果找到多个，再按照名称【id/name】找
     * org.springframework.beans.factory.annotation
     */
    @Autowired
    @Qualifier("dog1")
    private Dog dog;//



    public Person() {

    }
    public Person(String name, int age, Dog dog) {
        this.name = name;
        this.age = age;
        this.dog = dog;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public Dog getDog() {
        return dog;
    }
//    public void setDog(Dog dog) {
//        this.dog = dog;
//    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", dog=" + dog +
                '}';
    }
    //养
   public void keepDog(){
       System.out.println(name+"养狗======>：狗信息："+dog);
   }
}
